const models = require("../models/index.js");
const Brand = models.Brand;
const ApiError = require("../error/ApiError");
class BrandController {
  async create(req, res) {
    const { name } = req.body;
    const brand = await Brand.create({ name });
    return res.json({ message: "Бренд создан" });
  }
  async getAll(req, res) {
    const brands = await Brand.findAll();
    return res.json(brands);
  }
  async getOne(req, res) {
    const { id } = req.params;
    const brand = await Brand.findOne({ where: { id } });
    return res.json(brand);
  }
  async delete(req, res) {
    const { id } = req.params;
    const brand = await Brand.destroy({ where: { id } });
    return res.json({ message: "Бренд удален" });
  }
}

module.exports = new BrandController();
